using System;
using System.Collections.Generic;
using System.Text;

namespace LibGreen.Jabber.Enumerations
{
    /// <summary>
    /// Describes the type of contact presence information subscriptions
    /// </summary>
    public enum Subscription
    {
        /// <summary>
        /// The client has no subscription to the contact's presence information
        /// </summary>
        None,
        /// <summary>
        /// The client has a subscription to the contact's presence, but the contact does not have a subscription to the client's presence information
        /// </summary>
        To,
        /// <summary>
        /// The contact has a subscription to the client's presence, but the client does not have a subscription to the contact's presence information
        /// </summary>
        From,
        /// <summary>
        /// Both the contact and the client subscribe to each other's presence information
        /// </summary>
        Both
    }

    /// <summary>
    /// Contains static methods for converting strings to <see cref="Subscription"/> values, and vice versa
    /// </summary>
    static class SubscriptionConverter
    {
        /// <summary>
        /// Converts a <see cref="Subscription"/> value to a string
        /// </summary>
        /// <param name="subscription">A <see cref="Subscription"/> value to convert</param>
        /// <returns>A corresponding string suitable for network transmission</returns>
        public static string SubscriptionToString(Subscription subscription)
        {
            switch (subscription)
            {
                case Subscription.Both:
                    return "both";
                case Subscription.From:
                    return "from";
                case Subscription.None:
                    return "none";
                case Subscription.To:
                    return "to";
            }
            return "";
        }

        /// <summary>
        /// Converts a string to a <see cref="Subscription"/> value
        /// </summary>
        /// <param name="subscription">A received string to convert</param>
        /// <returns>A corresponding <see cref="Subscription"/> value</returns>
        public static Subscription StringToSubscription(string subscription)
        {
            switch (subscription)
            {
                case "both":
                    return Subscription.Both;
                case "from":
                    return Subscription.From;
                case "to":
                    return Subscription.To;
                default:
                    return Subscription.None;
            }
        }
    }
}
